using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace WPCoco.Graphics
{
    public class SwirlNode : TextureNode
    {
        public SwirlNode(AffineNode target, bool autoSize, Size gridSize)
            : base(target, autoSize)
        {
            grid = new VertexPositionColorTextureGrid(gridSize, new Size((int)Width, (int)Height));
        }

        public SwirlNode(AffineNode target, Size gridSize)
            : this(target, true, gridSize)
        {

        }

        public SwirlNode(AffineNode target)
            : this(target, new Size(10, 10))
        {

        }

        VertexPositionColorTextureGrid grid;

        Size gridSize;

        public Size GridSize
        {
            get { return gridSize; }
            set
            {
                if (gridSize == value) return;
                gridSize = value;
                grid.SetGridSize(value);
            }
        }

        Vector2 swirlCenter = Vector2.Zero;

        public Vector2 SwirlCenter
        {
            get { return swirlCenter; }
            set { swirlCenter = value; }
        }

        float swirlRadius = 100;

        public float SwirlRadius
        {
            get { return swirlRadius; }
            set { swirlRadius = value; }
        }

        float swirlRotation = 90;

        public float SwirlRotation
        {
            get { return swirlRotation; }
            set { swirlRotation = value; }
        }

        public override void DrawTexture(Texture2D texture, Size size)
        {
            grid.SetUsedTextureSize(size);
            grid.SetTextureSize(new Size((int)texture.Width, (int)texture.Height));
            grid.SwirlGridState(swirlCenter, swirlRadius, swirlRotation);
            grid.Draw(texture, WorldMatrix.Shared.CurrentMatrix);
        }
    }
}
